/**
 * 
 */   
package com.gson.inter;  

import java.io.IOException;
import java.io.OutputStreamWriter;

//import org.apache.commons.httpclient.HttpClient;
//import org.apache.commons.httpclient.HttpStatus;
//import org.apache.commons.httpclient.methods.GetMethod;

/**   
 * @作者 Stone
 * @创建日期 2013-10-17 下午06:41:55
 * @版本 V1.0
 * @类说明
 */
public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		getWeather("101050205");
	}
	
	private static void getWeather(String cityid){  
	    try{              
	        String url = "http://m.weather.com.cn/data/"+cityid+".html";  
	        String jsonString = getCityCode(url);  
	        System.out.println(jsonString);  
	    }catch(Exception ex){  
	        ex.printStackTrace();  
	    }  
	}
	
	public static String getCityCode(String url){  
	    try{  
//	        HttpClient httpClient = new HttpClient();  
//	        GetMethod mothod = new GetMethod(url);  
//	        mothod.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");  
//	        int statusCode = httpClient.executeMethod(mothod);  
//	        if(statusCode == HttpStatus.SC_OK){  
//	            return mothod.getResponseBodyAsString();  
//	        }  
	    }catch(Exception ex){  
	        ex.printStackTrace();  
	    }  
	    return null;  
	}
	
	private static void generateProvCode() {
		String provinceUrl = "http://m.weather.com.cn/data5/city.xml";  
		String provinceData = getCityCode(provinceUrl);  
		String[] provinceArray = provinceData.split(",");  
		for(String province: provinceArray){  
		    String[] provinceCodeArray = province.split("\\|");  
		    System.out.println(provinceCodeArray[0] + "," + provinceCodeArray[1]);  
		}  
	}
	
	private static void generateCityCode(String provinceCode) {  
	    String townUrl = "http://m.weather.com.cn/data5/city"+provinceCode+".xml";  
	    String townData = getCityCode(townUrl);  
	    String[] townArray = townData.split(",");  
	    for(String town: townArray){  
	        String[] townCodeArray = town.split("\\|");  
	        System.out.println("  " + townCodeArray[0] + "," + townCodeArray[1]);  
	    }  
	} 
	
	private static void generateCountyCode(String provinceCode, String townCode) {  
	    String countyUrl = "http://m.weather.com.cn/data5/city"+townCode+".xml";  
	    String countyData = getCityCode(countyUrl);  
	    String[] countyArray = countyData.split(",");  
	    for(String county: countyArray){  
	        String[] countyCodeArray = county.split("\\|");  
	        System.out.println("    " + countyCodeArray[0] + "," + countyCodeArray[1]);  
	          
	        //城市代码  
	        String codeUrl = "http://m.weather.com.cn/data5/city"+countyCodeArray[0]+".xml";  
	        String codeData = getCityCode(codeUrl);  
	        String[] codeArray = codeData.split("\\|");  
	        System.out.println(codeArray[1]);  
	    }  
	}  
	  
}
